let View = require("View")

let showed_notice = false

class LoginView extends View
{
    open()
    {
        require('NetProtocol').init()

        this.bindTouchEvent(this.mRoot, 'login', 
            () =>{
                
                let NetPrompt = require('NetPrompt')

                let nptId = NetPrompt.open()

                let us = require('UserSystem').share()
                
                us.login(null,
                    ()=>{

                        NetPrompt.close(nptId)
                        
                        let vm = require('ViewMan').share()
             
                        vm.translate('LoadingView', 
                            {
                                tasks : require('LoadingTasks').login(),
                                success : () =>{

                                    vm.push('HomeView', 
                                        ()=>{
                                            vm.pop('LoadingView')
                                        }
                                    )
                                }
                            }
                        )
                    },
                    ()=>{

                        NetPrompt.close(nptId)
                        
                        Log.w("login fail...")
                    }
                )
            }
        ) 

        this.bindTouchEvent(this.mRoot, 'notice', 
            () =>{
                
                this.mViewMan.push('NoticeView')
            },''
        ) 

        let t = this.widget('version')
        if (t)
        {
            t = t.getComponent(cc.Label)

            t.string = ogre.localize.get('TID_VERSION_F') + require("App").get(require('ConstBase').version)
        }

        if (!showed_notice)
        {
            showed_notice = true
            this.mViewMan.push('NoticeView')
        }        
    }
}

export default LoginView
